{% extends 'channel/base.html' %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
{% block content %}
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css">
    <script src="https://cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script>

    <div class="container">
        <div class="row clearfix">
            <div class="col-md-2 column">

            </div>
            <div class="col-lg-8">

                <div class="panel panel-default">
                    <!-- Default panel contents -->
                    <div class="panel-heading">渠道号列表</div>
                    <!-- Table -->
                    <table class="table table-bordered table-hover">
                        <thead>
                        <th>id</th>
                        <th>渠道号</th>
                        <th>渠道名</th>
                        <th>加固源</th>
                        <th>简称</th>
                        <th>更新时间</th>
                        <th>操作</th>

                        </thead>
                        <tbody>
                        {% for channel in list %}
                            <tr>
                                <td>{{ channel.id }}</td>
                                <td>{{ channel.code }}</td>
                                <td>{{ channel.name }}</td>
                                <td>{{ channel.jiagu }}</td>
                                <td>{{ channel.projectshortname }}</td>
                                <td>{{ channel.update_time }}</td>
                                <td>
                                    <div class="btn-group" role="group" aria-label="...">
                                        <button id="btn" type="button" class="btn btn-primary btn-xs">编辑</button>
                                        <button type="button" class="btn btn-primary btn-xs"
                                                onclick="del_channel({{ channel.id }})">删除
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>


                    </table>
                </div>
            </div>
            <div class="col-lg-2">

            </div>
        </div>
    </div>

    <script type="application/javascript">
        function del_channel(channel_id) {
            //Ajax CSRF认证使用，若不添加认证，django后端不识别
            // $.ajaxSetup({
            //      data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
            // })
            if (channel_id) {
                $.ajax({
                    url: "{% url 'channelnew:delChannelCode' %}",
                    type: 'POST',
                    dataType: 'json',
                    data: {'id': channel_id},
                    success: function (data) {
                        console.log(data);
                        toastr.success(data.msg);
                        location.reload()
                    }
                })
            }

        }

    </script>
    <style>
        .btn {
            margin-right: 10px;
        }
    </style>
{% endblock content %}
</body>
</html>